VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Begin VB.Form frm0file 
   Caption         =   "0-Length File Creator"
   ClientHeight    =   2100
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5385
   Icon            =   "frm0file.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   2100
   ScaleWidth      =   5385
   StartUpPosition =   3  'Windows Default
   Begin VB.OptionButton optFile 
      Caption         =   "Only this file"
      Enabled         =   0   'False
      Height          =   255
      Left            =   0
      TabIndex        =   7
      Top             =   840
      Value           =   -1  'True
      Width           =   1335
   End
   Begin VB.OptionButton optDir 
      Caption         =   "Entire directory"
      Enabled         =   0   'False
      Height          =   255
      Left            =   1320
      TabIndex        =   6
      Top             =   840
      Width           =   1455
   End
   Begin VB.Frame fraAbout 
      Height          =   975
      Left            =   0
      TabIndex        =   5
      Top             =   1080
      Width           =   5295
      Begin MSComDlg.CommonDialog cdgApri 
         Left            =   4440
         Top             =   120
         _ExtentX        =   847
         _ExtentY        =   847
         _Version        =   393216
      End
      Begin VB.Label Label1 
         Caption         =   $"frm0file.frx":0442
         Height          =   615
         Left            =   120
         TabIndex        =   8
         Top             =   240
         Width           =   4935
      End
   End
   Begin VB.CommandButton cmdGo 
      Caption         =   "Go"
      Height          =   255
      Left            =   3480
      TabIndex        =   4
      Top             =   840
      Width           =   1815
   End
   Begin VB.CommandButton cmdOutput 
      Caption         =   "Set Output Dir"
      Height          =   255
      Left            =   4080
      TabIndex        =   3
      Top             =   480
      Width           =   1215
   End
   Begin VB.CommandButton cmdInput 
      Caption         =   "Set Input File"
      Height          =   255
      Left            =   4080
      TabIndex        =   2
      Top             =   120
      Width           =   1215
   End
   Begin VB.TextBox txtOutput 
      Height          =   285
      Left            =   0
      TabIndex        =   1
      Top             =   480
      Width           =   3975
   End
   Begin VB.TextBox txtInput 
      Height          =   285
      Left            =   0
      TabIndex        =   0
      Top             =   120
      Width           =   3975
   End
End
Attribute VB_Name = "frm0file"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim InputFile As String
Dim OutputFile As String

'esegui il lavoro
Private Sub cmdGo_Click()
    If optFile.Value = True Then
        Call CreateStubFile(txtInput.Text, txtOutput.Text)
    Else
        Call ProcessaDirectory(Mid(txtInput.Text, 1, InStrRev(txtInput.Text, "\")), txtOutput.Text)
    End If
End Sub

'sceglia il file di input
Private Sub cmdInput_Click()
    optFile.Value = True
    cdgApri.InitDir = App.Path
    cdgApri.DialogTitle = "Choose the input file"
    cdgApri.ShowOpen
    If cdgApri.fileName <> vbNullString Then
        InputFile = cdgApri.fileName 'Mid(cdgApri.FileName, InStrRev(cdgApri.FileName, "\") + 1)
        txtInput.Text = InputFile
        If (txtOutput.Text <> vbNullString) Then
            optFile.Enabled = True
            optDir.Enabled = True
        End If
    End If
End Sub

'scegli il file di output
Private Sub cmdOutput_Click()
    optFile.Value = True
    cdgApri.InitDir = App.Path
    cdgApri.DialogTitle = "Choose the output file"
    cdgApri.ShowSave
    If cdgApri.fileName <> vbNullString Then
        OutputFile = cdgApri.fileName
        txtOutput.Text = OutputFile
        If (txtInput.Text <> vbNullString) Then
            optFile.Enabled = True
            optDir.Enabled = True
        End If
    End If
End Sub

'imposta il percorso di uscita come directory
Private Sub optDir_Click()
    OutputFile = Mid(OutputFile, 1, InStrRev(OutputFile, "\"))
    txtOutput.Text = OutputFile
    'InputFile = Mid(InputFile, 1, InStrRev(InputFile, "\"))
    'txtInput.Text = InputFile
End Sub

'ipmosta il percorso di uscita su un file
Private Sub optFile_Click()
    OutputFile = OutputFile & Mid(InputFile, InStrRev(InputFile, "\") + 1)
    txtOutput.Text = OutputFile
End Sub

'data una directory, crea uno stub per ogni file
Private Sub ProcessaDirectory(ByRef directory As String, ByRef outDir As String)
    Dim dir As Variant
    Dim t As Variant
    Dim item As Variant
    Set t = New FileSystemObject
    Set dir = t.GetFolder(directory)
    'dir.Path (directory)
    For Each item In dir.Files
        Call CreateStubFile(item.Name, outDir)
    Next item
    Set dir = Nothing
    Set t = Nothing
End Sub

'crea un file di lunghezza 0
Private Sub CreateStubFile(ByRef infileName As String, ByRef outfileName As String)
    Dim inFile As String
    Dim outDir As String
    inFile = Mid(infileName, InStrRev(infileName, "\") + 1)
    outDir = Mid(outfileName, 1, InStrRev(outfileName, "\"))
    Open outDir & inFile For Output As #2
    Close #2
End Sub
